package com.socialcoco.controller;


import com.socialcoco.entity.Comment;
import com.socialcoco.exception.myExection;
import com.socialcoco.respone.BaseResponse;
import com.socialcoco.respone.ResultUtils;
import com.socialcoco.respone.resultenum;
import com.socialcoco.serviceImpl.CommentServiceImpl;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Slf4j
@RestController
@RequestMapping("/socialcoco/user")
public class CommentController {
    @Autowired
    private CommentServiceImpl commentService;
    @ApiOperation("用户评论动态")
    @PostMapping("/saveComment")
    public BaseResponse<Object> saveComment(@RequestBody Comment comment,@RequestHeader("token")String token){
        comment.setUser(null);
        if(comment==null){
            throw new myExection(resultenum.BODY_NULL.getCode(),resultenum.BODY_NULL.getMsg());
        }
        log.info(comment.toString());
        comment.setCreateTime(new Date());
        commentService.save(comment);
        return ResultUtils.success("commentOk");
    }

}

